<template>
    <div>
        <van-nav-bar title="新增" left-text="返回" left-arrow @click-left="onClickLeft" />

        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="title" name="标题" label="标题" placeholder="标题"
                    :rules="[{ required: true, message: '请填写标题' }]" />
                    <van-field v-model="img" name="图片" label="图片" placeholder="图片"
                    :rules="[{ required: true, message: '请填写图片' }]" />
               
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter()

const onClickLeft = () => history.back();

const title = ref('')
const img = ref('')

const onSubmit = async (values) => {
    // console.log('submit', values);
    await axios.post('/api/list', { title: title.value, img: img.value })
    setTimeout(()=>{
        router.push({
            path: '/msg'
        })
    }, 1000)
};
</script>